
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QStandardItemModel>
#include <QLabel>
#include <QProgressBar>
#include <QMenu>
#include <QListWidget>
#include <QTimer>
#include "globalSetting.h"
#include "conditionTypes.h"


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow

{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    // initialize model tree
    void initValue();
    void initTreeView();
    void initStatusBar();
    void initSpliter();
    void initTreeTagList();
    void initConnect();
    QMenu *menuDefinitions;
    QMenu *menuGeometry;
    QMenu *menuMaterials;
    QMenu *menuHeatTransfer;
    QMenu *menuMesh;
    QMenu *menuSolver;
    QMenu *menuResult;
    QMenu *menuDataSet;
    QMenu *menuDeleteMaterial;
    QMenu *menuDeleteCondition;
    QMenu *menuDelete;
    QVector<QStandardItem*> materialSets;
    int materialIdx;
    QListWidget *materialSetting;
    QListWidget *solidSetting;
    QListWidget *areaPowerSetting;
    globalSetting *globalSet;

private slots:
    void slotMenuPopup(const QPoint &pos);
    void slotTreeViewClick(const QModelIndex &index);

    void addParameter();
    void addFunction();
    void addSelectSet();

    void addRectangle();
    void addSquare();
    void addCircle();
    void addEllipse();
    void addPolygen();
    void addSegment();
    void addArc();
    void addPoint();
    void addUnion();
    void addIntersection();
    void addDifference();

    void openMaterialDB();
    void addMaterial();

    void htAddHeatSource2D();
    void htAddVelocity();
    void htAddTemperature();
    void htAddThermalInsulation();
    void htAddHeatFlux();
    void htAddHeatSource1D();
    void htAddHeatConvection();
    void htAddHeatSource0D();

    void addMeshSize();
    void addTriangleMesh();
    void addQuadMesh();
    void addEdgeMesh();

    void addPathDataSet();
    void addPointDataSet();

    void addPlotGroup2D();
    void addPlotGroup1D();

    void deleteItems();
    void deleteDefinition();
    void deleteShape();
    void deleteMaterial();
    void deleteCondition();
    void deleteDataSet();
    void deletePlot();

    void setTitle(QString str);
    void setAuthor(QString str);
    void setDescription(QString str);

    void setLengthUnit(int index);
    void setAngleUnit(int index);

    void test();

private:
    Ui::MainWindow *ui;
    QStandardItemModel *_model;
    QStandardItem *_item;
    QTimer *_timer;
    QLabel *_memLabel;

    QSet<QString> _defineList;
    QSet<QString> _shapeList;
    QSet<QString> _materialList;
    QSet<QString> _htConditionList;
    QSet<QString> _meshSettingList;
    QSet<QString> _plotGroupList;
    QSet<QString> _subDataSetList;
    QVector<TreeTag::nodeTag> _treeTagList;

    void addNode(QSet<QString> &list, const int &itemIdx, const QString &namePrefix, const QIcon &icon);
    void addDataSet(QSet<QString> &list, const int &itemIdx, const QString &namePrefix, const QIcon &icon);
    bool checkIndexDeletable(QModelIndexList &idxList);
    void deleteNode(QModelIndex &idx);

    bool eventFilter(QObject *obj, QEvent *e);
};

#endif // MAINWINDOW_H
